<template>
    <div class="row">
        <el-checkbox v-model="comp.enabled">{{ comp.__classname__ }}</el-checkbox>
        <el-button round size="small" :icon="Document" @click="gm.toConsole(comp)"></el-button>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Color</el-text>
        <el-color-picker size="small" color-format="hex" show-alpha v-model="Model.color" />
        <el-input size="small" v-model="Model.color" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Content</el-text>
        <el-input size="small" type="textarea" v-model="comp.string" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>HorizontalAlign</el-text>
        <el-radio-group v-model="comp.horizontalAlign" size="small" class="width-full">
            <el-radio-button v-for="item in horizontalAlign.__enums__" :label="item.name" :value="item.value" />
        </el-radio-group>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>VerticalAlign</el-text>
        <el-radio-group v-model="comp.verticalAlign" size="small" class="width-full">
            <el-radio-button v-for="item in verticalAlign.__enums__" :label="item.name" :value="item.value" />
        </el-radio-group>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>FontSize</el-text>
        <el-input-number size="small" :controls="false" :step="0.1" v-model="comp.fontSize" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>LineHeight</el-text>
        <el-input-number size="small" :controls="false" :step="0.1" v-model="comp.lineHeight" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Overflow</el-text>
        <el-select v-model="comp.overflow" size="small">
            <el-option v-for="item in overflow.__enums__" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>EnableWrapText</el-text>
        <el-checkbox v-model="comp.enableWrapText" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>UseSystemFont</el-text>
        <el-checkbox v-model="comp.useSystemFont" />
        <el-input v-if="comp.useSystemFont" size="small" disabled :value="comp.fontFamily" />
        <el-input v-if="!comp.useSystemFont" size="small" disabled :value="gm.targetName(comp.font)" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>CacheMode</el-text>
        <el-select v-model="comp.cacheMode" size="small">
            <el-option v-for="item in cacheMode.__enums__" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Style</el-text>
        <el-check-tag v-model:checked="comp.isBold">Bold</el-check-tag>
        <el-check-tag v-model:checked="comp.isItalic">Italic</el-check-tag>
        <el-check-tag v-model:checked="comp.isUnderline">Underline</el-check-tag>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Outline</el-text>
        <el-checkbox v-model="comp.enableOutline" />
        <div v-if="comp.enableOutline" class="flex">
            <el-color-picker size="small" color-format="hex" show-alpha v-model="Model.outlineColor" />
            <el-input size="small" v-model="Model.outlineColor" />
            <el-input-number size="small" :controls="false" :step="0.1" v-model="comp.outlineWidth">
                <template #suffix>
                    <span>Width</span>
                </template>
            </el-input-number>
        </div>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Shadow</el-text>
        <el-checkbox v-model="comp.enableShadow" />
        <div v-if="comp.enableShadow" class="flex">
            <el-color-picker size="small" color-format="hex" show-alpha v-model="Model.shadowColor" />
            <el-input size="small" v-model="Model.shadowColor" />
            <el-input-number size="small" :controls="false" :step="0.1" v-model="comp.shadowBlur">
                <template #suffix>
                    <span>Blur</span>
                </template>
            </el-input-number>
        </div>
    </div>
    <div class="row-start" v-if="comp.enableShadow">
        <el-text class="span-title" />
        <el-input-number size="small" :controls="false" :step="0.1" v-model="Model.shadowOffsetX">
            <template #suffix>
                <span>X</span>
            </template>
        </el-input-number>
        <el-input-number size="small" :controls="false" :step="0.1" v-model="Model.shadowOffsetY">
            <template #suffix>
                <span>Y</span>
            </template>
        </el-input-number>
    </div>
</template>

<script lang="ts" setup>
import { Document } from '@element-plus/icons-vue'
import gm from './gm';

const props = defineProps<{
    comp: CCComponent,
    update: Number,
}>()
const horizontalAlign = cc.Label.HorizontalAlign
const verticalAlign = cc.Label.VerticalAlign
const overflow = cc.Label.Overflow
const cacheMode = cc.Label.CacheMode

class Model{
    static get comp() {
        return props.comp
    }

    static get color() {
        return gm.toHexColor(this.comp.color)
    }

    static set color(value: string) {
        this.comp.color = gm.toCCColor(value)
    }

    static get outlineColor() {
        return gm.toHexColor(this.comp.outlineColor)
    }

    static set outlineColor(value: string) {
        this.comp.outlineColor = gm.toCCColor(value)
    }

    static get shadowColor() {
        return gm.toHexColor(this.comp.shadowColor)
    }

    static set shadowColor(value: string) {
        this.comp.shadowColor = gm.toCCColor(value)
    }

    static get shadowOffsetX() {
        return this.comp.shadowOffset.x
    }

    static set shadowOffsetX(value: number) {
        const ori = this.comp.shadowOffset
        ori.x = value
        this.comp.shadowOffset = ori
    }

    static get shadowOffsetY() {
        return this.comp.shadowOffset.y
    }

    static set shadowOffsetY(value: number) {
        const ori = this.comp.shadowOffset
        ori.y = value
        this.comp.shadowOffset = ori
    }
}
</script>